package com.hscm.boss.mvc.model;


import com.hscm.boss.common.enums.ResponseCode;
import lombok.Data;

@Data
public class AjaxResult {

    private Integer code;
    private String msg;
    private Object data;


    /**
     *
     * @param data 代表返回给前端的数据
     * @return
     */
    public static  AjaxResult ok(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(ResponseCode.OK.getNumber());
        ajaxResult.setMsg(ResponseCode.OK.getMsg());
        ajaxResult.setData(data);

        return ajaxResult;
    }

    public static  AjaxResult ok(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(ResponseCode.OK.getNumber());
        ajaxResult.setMsg(ResponseCode.OK.getMsg());
        ajaxResult.setData("");

        return ajaxResult;
    }

    public static  AjaxResult fail(ResponseCode code){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code.getNumber());
        ajaxResult.setMsg(code.getMsg());
        ajaxResult.setData("");

        return ajaxResult;
    }
}
